﻿using System;
using System.Windows;
using System.Windows.Input;
using CommonControlLibrary;
using CommonControlLibrary.Common;

namespace SQLQuery.SplashScreen
{
    /// <summary>
    /// 
    /// </summary>
    public partial class SplashScreenWindow : Window, ISplash
    {
        public SplashScreenWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            this.board.Completed += OnAnimationCompleted;
        }

        #region Event Handlers
        void OnAnimationCompleted(object sender, EventArgs e)
        {
            this.board.Completed -= OnAnimationCompleted;
            DispatcherHelper.DoEvents();
            this.Close();
            
        }
        #endregion

        private void splashWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        #region ISplash 成员

        public void SetProgress(double index, string title)
        {
            progressBar.Value = index;
            if (!string.IsNullOrEmpty(title))
            {
                this.Info.Text = title;
            }
            DispatcherHelper.DoEvents();
        }

        public void CloseSplash()
        {
            this.board.Begin(this);
            //
        }

        #endregion
    }
}
